<template>
  <el-dialog
    :visible="visible"
    :before-close="handleClose"
    :show-close="true"
    :close="handleClose"
    :append-to-body="true"
    custom-class="related-dialog"
    class="small-common-dialog-size related-dialog"
  >
    <div class="title">以下供应商没有关联账号，关联失败</div>
    <div class="content">
      <div v-for="item in data" :key="item.supplierId" class="related-items">
        <div class="items-text">
          <ToolTip :content="item.supplierName" />
        </div>
        <el-button type="text" style="font-size: 14px;margin-right: 8px;" @click.native="toAdd(item.supplierId)">前往添加账号</el-button>
      </div>
    </div>
    <div class="center">
      <el-button
        type="primary"
        size="small"
        class="ok submit-btn"
        @click="handleClose"
      >
        确定
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  data() {
    return {
      visible: false,
      data: []
    };
  },
  methods: {
    openDialog(data) {
      if (data) {
        this.data = data;
      }
      this.visible = true;
    },
    toAdd(id) {
      const url = this.$router.resolve({
        name: 'supplierManageDetail',
        params: { id }
      });
      window.open(url.href, '_blank');
    },
    handleClose() {
      this.$emit('close');
      this.visible = false;
    }
  }
};
</script>

<style lang="scss" scoped>
.related-dialog {
  z-index: 999;
  .title {
    font-size: 16px;
    font-weight: bold;
  }
  .content {
    max-height: 398px;
    overflow: auto;
    .related-items {
      display: flex;
      justify-content: space-between;
      align-items: center;
      position: relative;
      .items-text {
        font-size: 14px;
        margin-right: 10px;
        width: 220px;
      }
      &:not(:last-child)::after {
        content: '';
        width: 100%;
        height: 1px;
        background-color: #EBEEFD;
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
      }
    }
  }
  .center {
    text-align: center;
  }
}
</style>
